﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RM.Common;
namespace RM.Web
{
    public partial class Center : PageBase
    {
        protected int totalCount;
        protected int page;
        protected int pageSize;
        protected string keywords = string.Empty;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            RM.BLL.RMConfig bll = new BLL.RMConfig();
            Model.RMConfig model = bll.GetModel(2);
            
            //this.pageSize = GetPageSize(10);//每页数量
            this.pageSize = int.Parse(model.ConfigValue);
            if (!Page.IsPostBack)
            {
                //检查权限
                //this.add.Visible = false;
                CheckPowerFailWithLinkButton(btnDelete);
                CheckPowerFailWithLinkButton(btnAdd);
                RptBind("id>0", "id asc");
                
            }
        }
        private void RptBind(string _strWhere, string _orderby)
        {
            this.page = DTRequest.GetQueryInt("page", 1);

            BLL.RMUsers bll = new BLL.RMUsers();
            this.rptList.DataSource = bll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount);
            this.rptList.DataBind();
            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("Center.aspx", "keywords={0}&page={1}",
               this.keywords, "__id__");
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
            
        }

        private int GetPageSize(int _default_size)
        {
            int _pagesize;
            if (int.TryParse(Utils.GetCookie("Users_page_size"), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    return _pagesize;
                }
            }
            return _default_size;
        }

        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int _pagesize;
            if (int.TryParse(txtPageNum.Text.Trim(), out _pagesize))
            {
                Utils.WriteCookie("User_page_size", _pagesize.ToString());
            }
            Response.Redirect(Utils.CombUrlTxt("Center.aspx", "keywords={0}", this.keywords));
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {

        }

        
        
    }
}